package com.dayu.tcp.count;

import lombok.Getter;
import lombok.ToString;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;

@ToString
@Getter
public class CountInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 最后接受消息时间
     */
    private final AtomicLong lastReceive = new AtomicLong();

    /**
     * 最后发送消息时间
     */
    private final AtomicLong lastSend = new AtomicLong();

    /**
     * 最大连接数
     */
    private final AtomicLong maxChannelNum = new AtomicLong();

    /**
     * 当前连接数
     */
    private final AtomicLong currChannelNum = new AtomicLong();

    /**
     * 接收消息数
     */
    private final AtomicLong receiveNum = new AtomicLong();

    /**
     * 发送消息数
     */
    private final AtomicLong sendNum = new AtomicLong();

    /**
     * 收发心跳数
     */
    private final AtomicLong heartbeatNum = new AtomicLong();

    public void setCurrChannelNum(long currChannelNum) {
        this.currChannelNum.set(currChannelNum);
        if (this.maxChannelNum.get() < currChannelNum) {
            this.maxChannelNum.set(currChannelNum);
        }
    }

    public void setLastSend(long lastSend) {
        if (this.lastSend.get() < lastSend) {
            this.lastSend.set(lastSend);
        }
    }

    public void setLastReceive(long lastReceive) {
        if (this.lastReceive.get() < lastReceive) {
            this.lastReceive.set(lastReceive);
        }
    }
}
